﻿@*page:App.razor*@
@*gardener-time:2024-07-16 16:11:31*@
@page "/app-manager/app"
@inherits ListOperateTableBase<AppDto, Guid, AppEdit,AppManagerResource>

@{
    TableFilter<IdentityType>[] identityTypeEnumFilters = EnumHelper.EnumToList<IdentityType>().Select(x => { return new TableFilter<IdentityType>() { Text = Localizer[EnumHelper.GetEnumDescriptionOrName(x)], Value = x }; }).ToArray();
}
<div>
    <Table @ref="_table"
        TItem="AppDto"
        DataSource="_datas"
        Total="_total"
        OnChange="OnChange"
        @bind-PageSize="_pageSize"
        @bind-SelectedRows="_selectedRows"
        Loading="_tableLoading.Value"
        Context="model"
        Size="ClientConstant.DefaultTableSize"
        PaginationPosition="@ClientConstant.TablePaginationPosition"
        RemoteDataSource>
            <TitleTemplate>
                <ResourceAuthorize ResourceKey="app_manager_app_search">
                    <TableSearch TDto="AppDto" @ref="this._tableSearch" OnSearch="OnTableSearch" Settings="_tableSearchSettings" CustomLocalizer="Localizer" />
                </ResourceAuthorize>
            <Row>
                <AntDesign.Col Span="8">
                    <ResourceAuthorize ResourceKey="app_manager_app_selected">
                        <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Delete" Danger OnClick="OnClickDeletes" Loading="_deletesBtnLoading">
                        @Localizer[nameof(SharedLocalResource.DeleteSelected)]
                        </Button>
                    </ResourceAuthorize>
                </AntDesign.Col>
                <AntDesign.Col Span="16" Style="text-align:right">
                    <Space>
                        <ResourceAuthorize ResourceKey="app_manager_app_add">
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Plus" OnClick="OnClickAdd">
                                @Localizer[nameof(SharedLocalResource.Add)]
                            </Button>
                        </SpaceItem>
                        </ResourceAuthorize>
                        <ResourceAuthorize ResourceKey="app_manager_app_refresh">
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Reload" OnClick="ReLoadTable">
                                @Localizer[nameof(SharedLocalResource.Refresh)]
                            </Button>
                        </SpaceItem>
                        </ResourceAuthorize>
                    </Space>
                </AntDesign.Col>
            </Row>
            </TitleTemplate>
            <ColumnDefinitions>
                <Selection Key="@model.Id.ToString()" Hidden="@_userUnauthorizedResources["app_manager_app_selected"]" />
                <Column @bind-Field="@model.Id" Filterable />
                <Column @bind-Field="@model.AppName" Filterable Sortable />
                <Column @bind-Field="@model.AppDescription" Filterable Sortable />
                <Column @bind-Field="@model.IsLocked"  Filterable Sortable>
                    <ResourceAuthorize ResourceKey="app_manager_app_lock">
                        <Authorized>
                            <Switch @bind-Value="@model.IsLocked" OnChange="e=>OnChangeIsLocked(model,e)" Loading="_lockBtnLoading[model]"></Switch>
                        </Authorized>
                        <NotAuthorized>
                            <TagYesNo Yes="model.IsLocked"></TagYesNo>
                        </NotAuthorized>
                    </ResourceAuthorize>
                </Column>
                    <Column @bind-Field="@model.CreatedTime"  Sortable DefaultSortOrder="@SortDirection.Descending" Format="@ClientConstant.DateTimeFormat"/>
                    <Column @bind-Field="@model.UpdatedTime"  Sortable Format="@ClientConstant.DateTimeFormat"/>
            <ActionColumn>
            <Space>
            <ResourceAuthorize ResourceKey="app_manager_app_edit">
            <SpaceItem>
                <Tooltip Title="@Localizer[nameof(SharedLocalResource.Edit)]" ArrowPointAtCenter="true">
                    <Button Icon="@IconType.Outline.Edit" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickEdit(model.Id)"></Button>
                </Tooltip>
            </SpaceItem>
            </ResourceAuthorize>
            <ResourceAuthorize ResourceKey="app_manager_app_detail">
            <SpaceItem>
                <Tooltip Title="@Localizer[nameof(SharedLocalResource.Detail)]" ArrowPointAtCenter="true">
                    <Button Icon="@IconType.Outline.Eye" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickDetail(model.Id)"></Button>
                </Tooltip>
            </SpaceItem>
            </ResourceAuthorize>
            <ResourceAuthorize ResourceKey="app_manager_app_delete">
                <SpaceItem>
                    <Tooltip Title="@Localizer[nameof(SharedLocalResource.Delete)]" ArrowPointAtCenter="true">
                        <Button Icon="@IconType.Outline.Delete" Type="@ButtonType.Primary" Danger OnClick="()=>OnClickDelete(model.Id)"></Button>
                    </Tooltip>
                </SpaceItem>
            </ResourceAuthorize>
            </Space> 
            </ActionColumn>
            </ColumnDefinitions>
        </Table>
</div>